const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that=this;
        
        wx.showShareMenu({
            menus: ['shareAppMessage', 'shareTimeline'],
            success(res) {
              console.log(res)
            },
            fail(e) {
              console.log(e)
            }
          })             
          var deviceInfo = wx.getDeviceInfo();
          console.log(deviceInfo)
          let d = app.globalData;
          this.getIndex();
          var open=wx.getStorageSync('open');  
          this.setData({
              //id:id,
              open:open,
              width:d.windowWidth,
              height:d.windowHeight,
              statusBarHeight:d.statusBarHeight,
              navHeight:d.navHeight,
              marginTop:d.navTitleTop,
              bottom:d.bottom,
              domain:d.domain,
              imgUrl:d.imgUrl,
              platform:deviceInfo.platform
          })
    },
    goBack(e){
        const pages = getCurrentPages();
          const prevPage = pages[pages.length - 2]; // 获取上一个页面实例
          console.log(prevPage);
          wx.navigateBack();
          //wx.navigateBack();
      },
      getIndex:function(){
        let that = this;    
        console.log('coupon----getIndex')  
        var store_id = wx.getStorageSync('store_id');
        var open = wx.getStorageSync('open');
        wx.request({
          url: app.globalData.domain+'/wechat/invite/Index',
          data:{from:1,user_id:open.user_id,open_id:open.id},
          success:res=>{
              console.log(res)
              var d=res.data;
           
            that.setData({
                procedure:d.procedure,
                invite:d.invite,
                reg:d.reg,
                order:d.order,
                buy:d.buy,
                rule:d.rule,
                title:d.title,
                money:d.money,
                shareImg:d.shareImg
         

            })
          }
      })

    },
    inputName(e){
        var value = e.detail.value;
        this.setData({
            name:value
        })
    },
    inputPhone(e){
        var value = e.detail.value;
        this.setData({
            phone:value
        })
    },
    invite:function(){
        let that = this;    
        let d = this.data;
        console.log('coupon----getIndex')  
        var store_id = wx.getStorageSync('store_id');
        var open = wx.getStorageSync('open');
        var invite = d.invite
        wx.request({
          url: app.globalData.domain+'/wechat/invite/Invite',
          data:{from:1,user_id:open.user_id,open_id:open.id,phone:d.phone,name:d.name},
          success:res=>{
              console.log(res)
              var d=res.data;
            if(d.code == 200){
                invite = invite+1;
            }
            app.showModal(d.msg,'#','#');
            that.setData({    
                invite:invite
            })
          }
      })

    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage(e) {
    var open = wx.getStorageSync('open');
    var parent_id=open.id;
    var store_id = wx.getStorageSync('store_id');
    var that = this;
    var title=this.data.title;
    var shareLogo=this.data.shareImg;
　  　var shareObj = {
　　　　title: title,    
　　　　path: '/pages/index/index?share=4&parent_id='+parent_id,   
　　　　imageUrl: shareLogo 
　　　
　　}
　　// 来自页面内的按钮的转发
　　if( e.from == 'button' ){
 　　　shareObj.title=title;
　　　　shareObj.path = '/pages/index/index?share=4&parent_id='+parent_id;
　　}
console.log(shareObj);
　　// 返回shareObj
　　return shareObj;

  }
})